package com.youka.bussiness.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import com.youka.bussiness.common.bean.RestResp;
import com.youka.bussiness.common.base.BaseEntity;
import com.youka.bussiness.common.base.BaseController;
import com.youka.bussiness.service.SysAdminService;
import com.youka.bussiness.service.req.SysAdminReqDto;
import com.youka.bussiness.service.req.SysAdminUpdateDto;
import com.youka.bussiness.service.req.SysAdminPageDto;
import com.youka.bussiness.service.res.SysAdminDto;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.List;

import java.util.Map;

/**
 * 管理员 Controller
 *
 * @author lfc
 * @date 2024-06-30 16:47:28
 */
@Api(tags = "app-管理员")
@RestController()
@RequestMapping("/app/SysAdmin")
public class SysAdminAppController extends BaseController{

    @Autowired
    private SysAdminService sysAdminService;

    /**
     * 查询管理员详情
     */
    @ApiOperation(value = "获取管理员详情")
    @PostMapping(value = "/single")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询管理员详情", response = SysAdminDto.class)
    })
    public RestResp findSysAdminById(@RequestBody BaseEntity entity) {
            SysAdminDto dto = sysAdminService.selectById(entity.getId());
        return success(dto);
    }

    /**
     * 查询管理员集合
     */
    @ApiOperation(value = "查询管理员集合")
    @PostMapping("/list")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询管理员详情", response = SysAdminDto.class)
    })
    public RestResp listSysAdmin(@RequestBody SysAdminReqDto sysAdminPageDto) {
        List<SysAdminDto> list = sysAdminService.selectByList(sysAdminPageDto);
        return success().toAdminTree(list);
    }

    /**
     * 查询管理员分页
     */
    @ApiOperation(value = "查询管理员分页")
    @PostMapping("/page")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询管理员详情", response = SysAdminDto.class)
    })
    public RestResp pageSysAdmin(@RequestBody SysAdminPageDto sysAdminPageDto) {
        IPage<SysAdminDto> page = sysAdminService.selectByPage(sysAdminPageDto);
        return success().toAdminPage(page);
    }

    /**
     * 新增管理员
     */
    @ApiOperation(value = "新增管理员")
    @PostMapping("/add")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询管理员详情", response = RestResp.class)
    })
    public RestResp addSysAdmin(@RequestBody SysAdminReqDto sysAdminReqDto) {
        sysAdminService.insert(sysAdminReqDto);
        return success();
    }

    /**
     * 编辑管理员
     */
    @ApiOperation(value = "编辑管理员")
    @PostMapping("/update")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询管理员详情", response = RestResp.class)
    })
    public RestResp updateSysAdmin(@RequestBody SysAdminUpdateDto sysAdminReqDto) {
        sysAdminService.update(sysAdminReqDto);
        return success();
    }

    /**
     * 删除管理员主键
     */
    @ApiOperation(value = "删除管理员")
    @PostMapping("/delete")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询管理员详情", response = RestResp.class)
    })
    public RestResp delete(@RequestBody BaseEntity entity) {
        sysAdminService.deleteById(entity.getId());
        return success();
    }
}
